package com.qfedu.dao;

import com.qfedu.model.Contractor;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;

public interface ContractorDao {

    //添加
    @Insert("insert into contractor (cname,updatetime,status) values(#{cname},#{updatetime},#{status})")
    void addContractor(Contractor contractor);

    //删除
    @Update("update contractor set status = 0 where cid = #{cid}")
    void deleteContractor(String cid);

    //修改
    @Update("update contractor set cname=#{cname},updatetime=#{updatetime},status=#{status} where cid = #{cid}")
    void updateContractor(Contractor contractor);

    //根据cid查询
    @Select("select * from contractor where status = 1 and cid = #{cid}")
    Contractor findByCid(String cid);

    //查询所有
    @Results(id = "findAllMap", value = {
            @Result(column = "cid",property = "cid"),
            @Result(column = "cname",property = "cname"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "status",property = "status"),
            @Result(column = "cid",property = "projects",
                    one = @One(select = "com.qf.dao.ProjectDao.findByCid",fetchType = FetchType.EAGER))
    })
    @Select("select * from contractor where status = 1")
    List<Contractor> findAll();
}